//
//  BCStuffThirdTableCell.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/16.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCStuffThirdTableCell.h"

@interface BCStuffThirdTableCell ()
{
    UIImageView *stuffImgView;
    UILabel *nameLab;
    UILabel *priceLab;
    UILabel *amountLab;
    UIView *backView;
}
@end

@implementation BCStuffThirdTableCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    stuffImgView = [[UIImageView alloc] init];
    stuffImgView.backgroundColor = [UIColor blackColor];
    nameLab = [[UILabel alloc] init];
    priceLab = [[UILabel alloc] init];
    priceLab.textColor = [UIColor colorWithRed:0.908  green:0.112  blue:0.114 alpha:1];
    
    amountLab = [[UILabel alloc] init];
    amountLab.font = [UIFont systemFontOfSize:20];
    amountLab.textAlignment = NSTextAlignmentCenter;
    self.plus = [UIButton buttonWithType:UIButtonTypeSystem];
    self.plus.backgroundColor = [UIColor colorWithRed:0.321  green:0.568  blue:0.390 alpha:1];
    self.minus = [UIButton buttonWithType:UIButtonTypeSystem];
    self.minus.backgroundColor =  self.plus.backgroundColor = [UIColor colorWithRed:0.321  green:0.568  blue:0.390 alpha:1];
    backView = [[UIView alloc] init];
    
    [backView addSubview:stuffImgView];
    [backView addSubview:nameLab];
    [backView addSubview:priceLab];
    [backView addSubview:amountLab];
    [backView addSubview:self.plus];
    [backView addSubview:self.minus];
    [self.contentView addSubview:backView];
}

- (void)layoutSubviews
{
    self.contentView.backgroundColor = [UIColor colorWithRed:0.972  green:0.973  blue:0.972 alpha:1];
    
    backView.backgroundColor = [UIColor whiteColor];
    stuffImgView.image = _stuffImg;
    nameLab.text = _name;
    priceLab.text = _price;
    amountLab.text = _amount;
    [self.plus setTitle:@"＋" forState:UIControlStateNormal];
    [self.minus setTitle:@"－" forState:UIControlStateNormal];
    self.plus.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    self.minus.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    self.plus.layer.cornerRadius = 10;
    self.minus.layer.cornerRadius = 10;
    self.plus.tintColor = [UIColor whiteColor];
    self.minus.tintColor = [UIColor whiteColor];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.and.right.equalTo(self.contentView);
        make.bottom.mas_equalTo(-5);
        
    }];
    
    [stuffImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.and.width.mas_equalTo(60);
        make.centerY.equalTo(backView);
        make.left.mas_equalTo(15);
    }];
    
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(stuffImgView.mas_top);
        make.left.mas_equalTo(123);
        make.height.mas_equalTo(26);
        make.width.mas_equalTo(100);
    }];
    
    [priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLab.mas_right).with.offset(32);
        make.top.equalTo(nameLab).with.offset(-1);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
    }];
    
    [amountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40);
        make.bottom.mas_equalTo(0);
        make.width.and.height.mas_equalTo(30);
    }];
    
    [self.plus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(amountLab.mas_right);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(amountLab.mas_bottom).with.offset(-5);
        make.height.and.width.mas_equalTo(20);
        
    }];
    
    [self.minus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(amountLab.mas_left);
        make.size.and.top.equalTo(self.plus);
        
    }];
    
    
    
}

@end
